package cn.edu.sasu.controller;

import cn.edu.sasu.common.base.LayuiRespResult;

import cn.edu.sasu.common.base.RespResult;
import cn.edu.sasu.common.constants.Constant;
import cn.edu.sasu.domain.dto.SysHospitalSaveDTO;
import cn.edu.sasu.domain.entity.SysHospital;
import cn.edu.sasu.service.SysHospitalService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 2024/4/27
 *
 * @author ganxue
 */
@RestController
@RequestMapping("/sys_hospital")
public class SysHospitalController {
    @Resource
    private SysHospitalService sysHospitalService;
    @GetMapping("/findSysHospitalAll")
    public LayuiRespResult findHospitalAll(Integer page, Integer limit){
        return sysHospitalService.hospitalList(page,limit);
    }
    @GetMapping("/findSysHospitals")
    public RespResult Hospitals(){
        List<SysHospital> deptList=sysHospitalService.getHospitals(Constant.DELETE_FLAG_YES);
        return RespResult.success(deptList);
    }
    @GetMapping("/findSysHospitalsById")
    public RespResult HospitalsById(Integer hospitalId){
        List<SysHospital> deptList=sysHospitalService.getHospitalsById(Constant.DELETE_FLAG_YES,hospitalId);
        return RespResult.success(deptList);
    }
    // 删除
    @PostMapping("/del")
    public RespResult del(Integer hospitalId){
        return sysHospitalService.delSysHospitalByUserId(hospitalId);
    }

    // 批量删除
    @PostMapping("/batchdel")
    public RespResult batchdel(Integer[] ids){
        return sysHospitalService.batchdel(ids);
    }

    // 搜索
    @GetMapping("/search")
    public LayuiRespResult search(Integer page,Integer limit,String hospitalName){
        return sysHospitalService.search(page,limit,hospitalName);
    }

    // 保存
    @PostMapping("/save")
    public RespResult save(@RequestBody @Validated SysHospitalSaveDTO SysHospitalSaveDTO){
        return sysHospitalService.save(SysHospitalSaveDTO);
    }
    // 更新
    @PostMapping("/update")
    public RespResult update(@RequestBody @Validated SysHospitalSaveDTO sysHospitalSaveDTO){
        return sysHospitalService.update(sysHospitalSaveDTO);
    }
}
